﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Xejen.Communication.NamedPipe.Client1.Test
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            await Task.Run(() =>
            {
                using (var pipeClient = new NamedPipeClientStream(".", "communicator", PipeDirection.In))
                {
                    Debug.WriteLine("客户端1-> 等待主进程指令...");

                    pipeClient.Connect();

                    using (var reader = new StreamReader(pipeClient))
                    {
                        string command = reader.ReadLine();
                        Debug.WriteLine($"客户端1-> 收到主进程指令：{{@value}}", command);

                        if (command == "Exit")
                        {
                            Debug.WriteLine("客户端1-> 处理指令Exit，子程序退出。");
                            MessageBox.Show("客户端1-> 处理指令Exit，子程序退出。");
                        }
                        else
                        {

                        }
                    }
                }
            });
        }
    }
}
